<template>
	<view class="myschool">
		<view class="edit_card">
			<view class="edit_op">
				<view class="flex">
					<view class="op_title">学校</view>
					<input class="edit_input_tag" v-model="schinfo.school" type="text" value="" maxlength="25"></input>
				</view>
			</view>
			<view class="edit_op">
				<view class="flex">
					<view class="op_title">学历</view>
					<input class="edit_input_tag" v-model="schinfo.education" type="text" value="" maxlength="25"></input>
				</view>				
			</view>
			<view class="edit_op" @tap="showpicker">
				<view class="flex">
					<view class="op_title">入学时间</view>
					<input class="edit_input_tag" v-model="schinfo.time" type="text" value="" :disabled="true" maxlength="25"></input>
				</view>				
			</view>
			<view class="edit_op">
				<view class="flex">
					<view class="op_title">专业</view>
					<input class="edit_input_tag" v-model="schinfo.major" type="text" value="" maxlength="25"></input>
				</view>
			</view>
		</view>
		
		<view class="" style="display: flex;  justify-content:center;">
			<view v-if="index" class="school_btn" @tap="resive">确认修改</view>
			<view v-else class="school_btn" @tap="submit">提交</view>
			<view v-if="index" class="school_btn1" @tap="resive1">确认删除</view>
		</view>
		
		<w-picker
		    mode="yearMonth" 
		    startYear="100"
		    endYear="2030"
		    :defaultVal="defaultVal" 
			:selectList="selectList"
		    :current="true" 
		    @confirm="onConfirm" 
		    ref="picker" 
		    themeColor="#5771FF"
		></w-picker>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				index:'',
				schinfo:{
					school:'',//学校
					major:'',//专业
					education:'',//学历
					time:'',//入学时间															
				},
				defaultVal:[],
				selectList:[],
			}
		},
		onLoad(option){
			this.index = option.index?option.index:'';
			if(option.index){
				this.schinfo = uni.getStorageSync("educational")[option.index];
			}
		},
		methods:{
			showpicker(){
				this.$refs.picker.show();
			},
			onConfirm(e){	
				this.schinfo.time = e.result;
			},
			//提交
			submit(){
				if(!this.schinfo.school){
					this.$api.msg('请输入学校~')
					return false;
				}
				if(this.grade==2&&!this.schinfo.education){
					this.$api.msg('请输入学历~')
					return false;
				}
				if(!this.schinfo.time){
					this.$api.msg('请输入入学时间~')
					return false;
				}
				let educational = uni.getStorageSync("educational");
				if(educational==''){
					educational = [];
				}
				educational.push(this.schinfo);
				uni.setStorageSync("educational",educational);
				uni.navigateBack()
			},
			//修改
			resive(){
				let educational = uni.getStorageSync("educational");
				educational[this.index] = this.schinfo;
				uni.setStorageSync("educational",educational);
				uni.navigateBack();
			},
			resive1(){
				let educational = uni.getStorageSync("educational");
				 educational.splice(this.index, 1);
				uni.setStorageSync("educational",educational);
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss">
	@import "./myschool.scss"
</style>